<?php

class Common extends Module
{
	function __construct ($db){
		$this->set_db($db);
	}

	function evaluation($result, $assessment){
		if($result <= $assessment['p1']){
			$evaluation = 1;
		}elseif($result <= $assessment['p2']){
			$evaluation = 2;
		}elseif($result <= $assessment['p3']){
			$evaluation = 3;
		}elseif($result <= $assessment['p4']){
			$evaluation = 4;
		}else{
			$evaluation = 5;
		}
		return $evaluation;
	}

	function get_variable($formula){

		$result = "";

		$tmp = explode("{", $formula);

		for($i = 1; $i < count($tmp); $i++){
			$a = split("}",$tmp[$i]);
			$result .= trim($a[0]).",";
		}

		$result = substr($result,0,-1);

		return $result;
	}

	function get_common($p){

		$variable = explode(",", $p);
		$result = array();

		foreach($variable as $k => $v){
			$tmp = explode(".", $v);
			$sql = "SELECT name FROM common WHERE gid = ".$tmp[0]." order by id asc LIMIT ".($tmp[1]-1).",1";
			$result[$k]['name'] = $this->db->queryUniqueValue($sql);
			$result[$k]['variable'] = $v;
		}

		return $result;
	}
}

?>